﻿Imports Castle.ActiveRecord
Imports NHibernate
Imports NHibernate.Criterion

Namespace Model

    <Serializable(), ActiveRecord("produto")> _
    Public Class ProdutoPesquisa
        Inherits ActiveRecordBase(Of Model.ProdutoPesquisa)


        Enum ProdutoStatus As Short
            Ativo = 0
            Inativo = 1
        End Enum

        Private _cd_produto As Integer

        Private _Grupo As Grupo
        Private _Unidade As Unidade
        Private _Ncm As Ncm

        Private _pr_nome As String
        Private _pr_fabricante As String
        Private _pr_barra As String

        Private _pr_custo As Decimal
        Private _pr_venda As Decimal

        Private _pr_inclusao As Date
        Private _pr_entrada As Date
        Private _pr_saida As Date
        Private _pr_inativo As Short

        Private _pr_peso_bruto As Decimal
        Private _pr_peso_liquido As Decimal

        Private _pr_foto As String
        Private _pr_observacao As String

        Private _pr_tipo As Short ' Pro ou Serv
        Private _pr_num_item As Short ' Veiculo, Mecamento, Arma

        Private _pr_aliq_ii As Decimal
        Private _pr_aliq_ipi As Decimal
        Private _pr_aliq_pis As Decimal
        Private _pr_aliq_pis_st As Decimal
        Private _pr_aliq_cofins As Decimal
        Private _pr_aliq_cofins_st As Decimal
        Private _pr_aliq_icms As Decimal
        Private _pr_aliq_icms_st As Decimal
        Private _pr_aliq_issqn As Decimal
        Private _pr_cst As String

        Private _pr_perigoso As Short

        Private _pr_embalagem As String
        Private _pr_embalagem_quantidade As Decimal


        <PrimaryKey(PrimaryKeyType.Sequence, SequenceName:="produto_cd_produto_seq")> _
        Public Property cd_produto() As Integer
            Get
                Return _cd_produto
            End Get
            Set(ByVal value As Integer)
                _cd_produto = value
            End Set
        End Property

        <BelongsTo("cd_grupo")> _
        Public Property Grupo() As Grupo
            Get
                Return _Grupo
            End Get
            Set(ByVal value As Grupo)
                _Grupo = value
            End Set
        End Property

        <BelongsTo("cd_unidade")> _
        Public Property Unidade() As Unidade
            Get
                Return _Unidade
            End Get
            Set(ByVal value As Unidade)
                _Unidade = value
            End Set
        End Property

        <BelongsTo("cd_ncm")> _
        Public Property Ncm() As Ncm
            Get
                Return _Ncm
            End Get
            Set(ByVal value As Ncm)
                _Ncm = value
            End Set
        End Property

        <[Property]("pr_nome")> _
        Public Property pr_nome() As String
            Get
                Return _pr_nome
            End Get
            Set(ByVal value As String)
                _pr_nome = value
            End Set
        End Property

        <[Property]("pr_fabricante")> _
        Public Property pr_fabricante() As String
            Get
                Return _pr_fabricante
            End Get
            Set(ByVal value As String)
                _pr_fabricante = value
            End Set
        End Property

        <[Property]("pr_barra")> _
        Public Property pr_barra() As String
            Get
                Return _pr_barra
            End Get
            Set(ByVal value As String)
                _pr_barra = value
            End Set
        End Property

        <[Property]("pr_custo")> _
        Public Property pr_custo() As Decimal
            Get
                Return _pr_custo
            End Get
            Set(ByVal value As Decimal)
                _pr_custo = value
            End Set
        End Property

        <[Property]("pr_venda")> _
        Public Property pr_venda() As Decimal
            Get
                Return _pr_venda
            End Get
            Set(ByVal value As Decimal)
                _pr_venda = value
            End Set
        End Property

        <[Property]("pr_inclusao", ColumnType:="Date")> _
        Public Property pr_inclusao() As Date
            Get
                Return _pr_inclusao
            End Get
            Set(ByVal value As Date)
                _pr_inclusao = value
            End Set
        End Property

        <[Property]("pr_entrada", ColumnType:="Date")> _
        Public Property pr_entrada() As Date
            Get
                Return _pr_entrada
            End Get
            Set(ByVal value As Date)
                _pr_entrada = value
            End Set
        End Property

        <[Property]("pr_saida", ColumnType:="Date")> _
        Public Property pr_saida() As Date
            Get
                Return _pr_saida
            End Get
            Set(ByVal value As Date)
                _pr_saida = value
            End Set
        End Property

        <[Property]("pr_inativo")> _
        Public Property pr_inativo() As Short
            Get
                Return _pr_inativo
            End Get
            Set(ByVal value As Short)
                _pr_inativo = value
            End Set
        End Property

        <[Property]("pr_peso_bruto")> _
        Public Property pr_peso_bruto() As Decimal
            Get
                Return _pr_peso_bruto
            End Get
            Set(ByVal value As Decimal)
                _pr_peso_bruto = value
            End Set
        End Property

        <[Property]("pr_peso_liquido")> _
        Public Property pr_peso_liquido() As Decimal
            Get
                Return _pr_peso_liquido
            End Get
            Set(ByVal value As Decimal)
                _pr_peso_liquido = value
            End Set
        End Property

        <[Property]("pr_foto")> _
        Public Property pr_foto() As String
            Get
                Return _pr_foto
            End Get
            Set(ByVal value As String)
                _pr_foto = value
            End Set
        End Property

        <[Property]("pr_observacao")> _
        Public Property pr_observacao() As String
            Get
                Return _pr_observacao
            End Get
            Set(ByVal value As String)
                _pr_observacao = value
            End Set
        End Property

        <[Property]("pr_tipo")> _
        Public Property pr_tipo() As Short
            Get
                Return _pr_tipo
            End Get
            Set(ByVal value As Short)
                _pr_tipo = value
            End Set
        End Property

        <[Property]("pr_num_item")> _
        Public Property pr_num_item() As Short
            Get
                Return _pr_num_item
            End Get
            Set(ByVal value As Short)
                _pr_num_item = value
            End Set
        End Property

        <[Property]("pr_aliq_ii")> _
        Public Property pr_aliq_ii() As Decimal
            Get
                Return _pr_aliq_ii
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_ii = value
            End Set
        End Property

        <[Property]("pr_aliq_ipi")> _
        Public Property pr_aliq_ipi() As Decimal
            Get
                Return _pr_aliq_ipi
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_ipi = value
            End Set
        End Property

        <[Property]("pr_aliq_pis")> _
        Public Property pr_aliq_pis() As Decimal
            Get
                Return _pr_aliq_pis
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_pis = value
            End Set
        End Property

        <[Property]("pr_aliq_pis_st")> _
        Public Property pr_aliq_pis_st() As Decimal
            Get
                Return _pr_aliq_pis_st
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_pis_st = value
            End Set
        End Property

        <[Property]("pr_aliq_cofins")> _
        Public Property pr_aliq_cofins() As Decimal
            Get
                Return _pr_aliq_cofins
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_cofins = value
            End Set
        End Property

        <[Property]("pr_aliq_cofins_st")> _
        Public Property pr_aliq_cofins_st() As Decimal
            Get
                Return _pr_aliq_cofins_st
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_cofins_st = value
            End Set
        End Property

        <[Property]("pr_aliq_icms")> _
        Public Property pr_aliq_icms() As Decimal
            Get
                Return _pr_aliq_icms
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_icms = value
            End Set
        End Property

        <[Property]("pr_aliq_icms_st")> _
        Public Property pr_aliq_icms_st() As Decimal
            Get
                Return _pr_aliq_icms_st
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_icms_st = value
            End Set
        End Property

        <[Property]("pr_aliq_issqn")> _
        Public Property pr_aliq_issqn() As Decimal
            Get
                Return _pr_aliq_issqn
            End Get
            Set(ByVal value As Decimal)
                _pr_aliq_issqn = value
            End Set
        End Property

        <[Property]("pr_cst")> _
        Public Property pr_cst() As String
            Get
                Return _pr_cst
            End Get
            Set(ByVal value As String)
                _pr_cst = value
            End Set
        End Property

        <[Property]("pr_embalagem")> _
        Public Property pr_embalagem() As String
            Get
                Return _pr_embalagem
            End Get
            Set(ByVal value As String)
                _pr_embalagem = value
            End Set
        End Property

        ''' <summary>
        ''' Retorna uma lista de produtos buscando pelo nome com like
        ''' </summary>
        ''' <param name="Nome">Parte do nome do produto que deseja buscar</param>
        ''' <returns>Lisca de produtos encontrados com o nome informado</returns>
        ''' <remarks>Ignora o case sensitive</remarks>
        Public Function GetByNome(ByVal Nome As String) As IList(Of Model.ProdutoPesquisa)
            Dim q As DetachedCriteria = DetachedCriteria.For(Of Model.ProdutoPesquisa)("produto")

            q.Add(Restrictions.Like("pr_nome", Nome, MatchMode.Anywhere).IgnoreCase())
            'q.Add(Restrictions.Eq("pr_inativo", CType(Model.ProdutoPesquisa.ProdutoStatus.Ativo, Short)))

            Return Model.ProdutoPesquisa.FindAll(q)
        End Function

        ''' <summary>
        ''' Produtos Ativos ou Inativos podem ser retornados por esta função
        ''' 
        ''' </summary>
        ''' <param name="ProdutoStatus">Ativo ou Inativo</param>
        ''' <returns>Lista dos Ativos ou Inativos</returns>
        ''' <remarks>Os dois não são retornados</remarks>
        Public Function GetByProdutoStatus(ByVal ProdutoStatus As Model.ProdutoPesquisa.ProdutoStatus) As IList(Of Model.ProdutoPesquisa)
            Dim q As DetachedCriteria = DetachedCriteria.For(Of Model.ProdutoPesquisa)("produto")
            q.Add(Restrictions.Eq("pr_inativo", CType(ProdutoStatus, Short)))

            Return Model.ProdutoPesquisa.FindAll(q)
        End Function


    End Class
End Namespace
